package com.dq.Week3.day15;

/**
 * try catch finally 案例
 */
public class ExceptionDemo04 {
    public static void main(String[] args) {

        int c = 0;
        try {
            c = add(1, 2);
        } catch (Exception e) {
            System.out.println("调用add方法时出现了异常，异常为"+e);
        }

        System.out.println(c);
    }

    public static int add(int a,int b){
        try {
            int c = 1/0;
            return a+b;
        }catch (ArithmeticException e){
            System.out.println("产生了数学异常");
            throw new RuntimeException("add出异常了");
//            return 5;
        }
        catch (Exception e){
            System.out.println("产生了异常");
        }
        finally {
            System.out.println("finally中的代码");
//            return 6;
        }
        return 0;
    }
}